#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
using std::cout;
using std::vector;
using std::endl;
using std::string;
using std::ifstream;
using std::istringstream;
class Config{
public:
    Config(string key,string value)
    :_key(key)
    ,_value(value)
    {

    }
public:
    string _key;
    string _value;
};
class AliyunConfig{
public:
    static AliyunConfig * getInstance(){
        if(!_ps){
            _ps=new AliyunConfig();
        }
        return _ps;
    }
    //存入对象
   void put(string key,string value){
       //在容器末尾添加一个的config元素
       _configPairs.push_back(Config(key,value));
   }
   string get(const string& key){
       for(auto &ele:_configPairs){
           if(key==ele._key){
               return ele._value;
           }
       }
       static string emptyStr;
       return emptyStr;

   }
    AliyunConfig(const AliyunConfig &rhs)=delete;
    AliyunConfig & operator=(const AliyunConfig& rhs);
private:
    AliyunConfig(){}
    static AliyunConfig* _ps;
    vector<Config> _configPairs; 
};
AliyunConfig *AliyunConfig::_ps;

void test(){
ifstream ifs("aliyun.conf");
if(!ifs){
    cout<<"no such a file"<<endl;
    return ;
}
string line;
while(getline(ifs,line)){
    istringstream iss(line);
    string key,value;
    iss>>key>>value;
    AliyunConfig::getInstance()->put(key,value);
}
cout<<AliyunConfig::getInstance()->get("ip")<<endl;;
cout<<AliyunConfig::getInstance()->get("port")<<endl;;
cout<<AliyunConfig::getInstance()->get("username")<<endl;;
cout<<AliyunConfig::getInstance()->get("password")<<endl;;

}
    
int main(int argc, char * argv[]){
    test();
    return 0;
}

